<% layout('/layouts/default.html', {title: '文件分发管理', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-notebook"></i> ${text('文件待领文列表')}
            </div>
            <div class="box-tools pull-right">

              <!--  <a href="${ctx}/sd/collectPicture/form" class="btn btn-default btnTool" title="${text('身份识别')}"><i class="icon-user -following"></i> ${text('身份识别')}</a>-->

                <a href="#" class="btn btn-default"  title="${text('领文')}" onclick="sendDoc()"><i class="fa fa-send-o"></i> ${text('送文')}</a>
                <a href="#" class="btn btn-default"  title="${text('领文')}" onclick="viewDoc()"><i class="fa fa-hand-lizard-o"></i> ${text('领文')}</a>
                <a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>

            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${docDeliverRecord}" action="${ctx}/sd/docDeliverWaitTake/listData" method="post" class="form-inline hide"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div class="form-group">
                <label class="control-label">${text('来文自编号')}：</label>
                <div class="control-inline">
                    <#form:input path="docRecv.docSysCode" maxlength="64" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('文件标题')}：</label>
                <div class="control-inline">
                    <#form:input path="docRecv.docTitle" maxlength="4" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('紧急程度')}：</label>
                <div class="control-inline" style="width: 80px">
                    <#form:select path="docRecv.docEmergLvl"  dictType="recv_doc_emerg_lvl" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('领文单位')}：</label>

                <div class="control-inline width-120">
                    <#form:treeselect id="unit" title="领文单位选择" path="recvUnitCode"
                    url="${ctx}/sd/docDeliverRecord/treeData" class="" allowClear="true" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('单位类型')}：</label>

                <div class="control-inline width-120">
                    <#form:select path="deliverType" id="lx" dictType="sd_deliver_send_take" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('密级')}：</label>
                <div class="control-inline width-120">
                    <#form:select path="docRecv.secLvl" dictType="recv_sec_lvl" blankOption="true" class="form-control"/>
                </div>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
                <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
            </div>
        </#form:form>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
</div>
<% } %>
<script src="${ctxStatic}/common/des.js?${_version}"></script>
<script>

    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text("来文自编号")}', name:'docRecv.docSysCode', index:'c.doc_sys_code', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
                    return '<a href="${ctx}/sd/docDeliverWaitTake/form?id='+row.id+'" class="btnList" data-title="${text("编辑文件分发")}">'+(val||row.id)+'</a>';
                }},
            {header:'${text("文件文号")}', name:'docRecv.docFullNum', index:'c.doc_full_num', width:150, align:"center"},
            {header:'${text("文件分发编号")}', name:'docCopyNo', index:'doc_copy_no', width:150, align:"center"},
            {header:'${text("文件标题")}', name:'docRecv.docTitle', index:'c.doc_title', width:150, align:"center"},
            {header:'${text("来文时间")}', name:'docRecv.docRecvDate', index:'c.doc_recv_date', width:150, align:"center"},
            {header:'${text("密级")}', name:'docRecv.secLvl', index:'c.sec_lvl', width:80, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('recv_sec_lvl')}, val, '${text("未知")}', true);
                }},
            {header:'${text("紧急程度")}', name:'docRecv.docEmergLvl', index:'c.doc_emerg_lvl', width:150, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('recv_doc_emerg_lvl')}, val, '${text("未知")}', true);
                }},
            {header:'${text("领文截止时间")}', name:'beforeTakeDate', index:'before_take_date', width:150, align:"center",formatter: function(val, act){
                      var date=new Date();
                      var t=date.getTime();
                      var oldTime = (new Date(val)).getTime()

                            if (t>oldTime) {
                                return '<font style="color: red">'+val+'</font>';
                            }
                            return val;
                    }

                },
            {header:'${text("单位类型")}', name:'deliverType', index:'a.deliver_type', width:150, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sd_deliver_send_take')}, val, '${text("未知")}', true);
                }},
            {header:'${text("领文单位")}', name:'office.officeName', index:'o.office_name', width:150, align:"center"},
            {header:'${text("领文单位柜号")}', name:'office.extend.extendS4', index:'o.extend_s4', width:150, align:"center"},



            {header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
                    var actions = [];
                <% if(hasPermi('sd:docDeliverWaitTake:edit')){ %>
                        actions.push('<a href="${ctx}/sd/docDeliverWaitTake/form?id='+row.id+'" class="btnList" title="${text("查看")}"><i class="fa fa-search"></i></a>&nbsp;');
                    <% } %>
                    return actions.join('');
                }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
    function sendDoc(){
        js.layer.open({
            type: 2,
            area: [(js.layer.window.outerWidth-150)+'px',(js.layer.window.outerHeight-150)+'px'],
            title: '${text("送文件")}',
            resize: false,
            scrollbar: true,
            maxmin:true,
            content: '${ctx}/sd/docDeliverWaitTake/sendDoc',
            success: function(layero, index){

            },
            btn: ['<i class="fa fa-check"></i> ${text("送文")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
           btn1: function (index, layero) {
            var win = layero.iframeWindow();
            var form = {
                inputForm: win.$('#inputForm'),
                btnSubmit: win.$('#btnSubmit'),
            }
            if(win.$("#testOfficeName").val()==""){
                js.layer.msg("送文单位不能为空",{icon:1})
                return false;
            }
               if(win.$("#userName").val()==""){
                   js.layer.msg("送文单位不能为空",{icon:1})
                   return false;
               }
               if(win.$("#police").val()==""){
                   js.layer.msg("送文单位不能为空",{icon:1})
                   return false;
               }
               if(win.$("#face").val()==""){
                   js.layer.msg("请先拍照",{icon:1})
                   return false;
               }
               js.ajaxSubmitForm(form.inputForm, function(data){
                   if(data.result == Global.TRUE){
                       js.layer.msg(data.message, {icon: 1});
                       js.layer.closeAll();
                       page();
                       return true;
                   }else{
                       js.layer.msg(data.message, {icon: 1});
                       js.layer.closeAll();
                       page();
                       return true;

                   }
                   page();
               }, "json");
               return false;

           }


        })
    }
    function viewDoc() {
        js.layer.open({
            type: 2,
            area: [(js.layer.window.outerWidth-150)+'px',(js.layer.window.outerHeight-150)+'px'],
            title: '${text("领取文件")}',
            resize: false,
            scrollbar: true,
            maxmin:true,
            content: '${ctx}/sd/docDeliverWaitTake/viewDoc',
            success: function(layero, index){

            },
            btn: ['<i class="fa fa-check"></i> ${text("保存")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function (index, layero) {
               var win = layero.iframeWindow();
               var form = {
                   inputForm: win.$('#inputForm'),
                   btnSubmit: win.$('#btnSubmit'),
               };
                let secretKey = '${@Global.getConfig("shiro.loginSubmit.secretKey")}';
               win.$('#userId').val(DesUtils.encode(win.$('#userId').val(), secretKey));


                //给密码加密
               // alert(win.$('#userId').val())
                //临时领文


                      if(win.$('#userId').val() === ''){
                          js.layer.msg('请输入保密人密码', {icon: 5});

                          return false;
                      }

                  if(win.$('#xm').val() ===''||win.$('#jx').val() === '') {
                      js.layer.msg('姓名或者警号不能为空!', {icon: 5});
                      return false;
                  }
                      if (win.$('#testOfficeCode').val() === '') {
                                 js.layer.msg('领文单位不能为空!', {icon: 5});
                                 return false;
                            }



                  if(win.$('#testUserCode').val() === ''){
                      js.layer.msg('请选择领文人', {icon: 5});

                      return false;
                  }

              if (win.$('#pictureSrc').val() === ''){
                  console.log(win.$('#pictureSrc').val())
                  js.layer.msg("请先提交照片", {icon: 5})
                  return false;

              }



                js.ajaxSubmitForm(form.inputForm, function(data){
                    if(data.result == Global.TRUE){
                        js.layer.msg(data.message, {icon: 1});
                        js.layer.closeAll();
                        page();
                        return true;
                    }else{
                        win.$('#userId').val("")
                        js.layer.msg(data.message, {icon: 5});


                    }
                    page();
                }, "json");
             return false;

           }


        });
    }
</script>